fix: prevent stale activityRelations in affiliations refresh (CM-1132)#4088
fix: prevent stale activityRelations in affiliations refresh (CM-1132)#4088
Conversation
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
1 similar comment
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
There was a problem hiding this comment.
Pull request overview
This PR fixes a correctness issue in affiliation refresh where memberSegmentAffiliations (manual, segment-scoped) could prevent updates to activityRelations in other segments, leaving stale organizationId values. The approach splits affiliation processing into a global “base” pass (member organizations only) plus per-segment “manual” passes, and ensures the base pass skips rows covered by manual affiliations.
Changes:
- Extend
TimelineItemwithskipManualAffiliationSegmentsto control base-pass skipping behavior. - Split timeline building into base (global) vs manual (per segment) passes, and discard manual “gap” items.
- Update the activityRelations update query to use alias-qualified columns and add a
NOT EXISTSguard to avoid overwriting rows covered by manual affiliations.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| services/libs/data-access-layer/src/member-organization-affiliation/types.ts | Adds skipManualAffiliationSegments to timeline items to support multi-pass processing. |
| services/libs/data-access-layer/src/member-organization-affiliation/index.ts | Splits timeline generation into base/manual passes and updates the batch update query with manual-coverage skipping logic. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
…imeline func Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>
|
Your PR title doesn't contain a Jira issue key. Consider adding it for better traceability. Example:
Projects:
Please add a Jira issue key to your PR title. |
epipav
left a comment
There was a problem hiding this comment.
looks good 👍 added one comment
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, have a team admin enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit bb9c576. Configure here.
Signed-off-by: Yeganathan S <63534555+skwowet@users.noreply.github.com>

Summary
When a member had
memberSegmentAffiliations(MSA) rows, the affiliation timeline builder mixed them together withmemberOrganizationsinto a single timeline.selectPrimaryWorkExperiencewould pick the MSA as the primary org for any overlapping date range (MSAs have highest precedence), producing aTimelineItemwith asegmentId.processAffiliationActivitiesthen appliedWHERE segmentId = Xfor that item, so activities in other segments were never updated. This left staleorganizationIdvalues inactivityRelationsfor the unprocessed segments.What changed
The timeline is now split into two passes:
Base timeline
Built from
memberOrganizationsonly, without asegmentId, and applies globally across all segments. When MSAs exist, each item is flagged withskipManualAffiliationSegments.Manual timeline
Built per MSA group (grouped by
segmentId), with each item scoped to its segment. Gap items (null org) are discarded since the base timeline already covers those date ranges.In
processAffiliationActivities, theskipManualAffiliationSegmentsflag adds aNOT EXISTS (SELECT 1 FROM memberSegmentAffiliations ...)condition so the base pass skips activity rows already covered by an MSA. Those rows are then handled by the manual pass.This ensures every
activityRelationsrow is updated exactly once, with no double updates and no missed rows.Note
Medium Risk
Touches timeline generation and the SQL update criteria used to rewrite
activityRelations.organizationId, so mistakes could mis-assign orgs or skip updates across segments despite being a targeted fix.Overview
Fixes affiliation refresh so
activityRelationsupdates don’t get skipped for members withmemberSegmentAffiliations.The timeline build is split into a global base pass (from
memberOrganizations) and a per-segment manual pass (from MSAs). Base items can be flagged withskipManualAffiliationSegments, andprocessAffiliationActivitiesnow adds aNOT EXISTSguard so the base pass won’t overwrite rows covered by MSAs; the manual pass then updates those segment-scoped rows. Also adds an option to omit fallback ranges when building manual timelines and removes redundant try/catch wrappers in the enrichment worker activity functions.Reviewed by Cursor Bugbot for commit 8261823. Bugbot is set up for automated code reviews on this repo. Configure here.